Page({
  data: {
    list: [],
    isFirstLoad: true
  },

  onLoad() {
    this.getRoom()


  },

  async getRoom() {
    let res = await wx.http.get('/room')
    console.log(res)
    this.setData({
      list: res,
      isFirstLoad: false
    })
  },

  async swipeClose(ev) {
    const { position, instance } = ev.detail
    let id = ev.mark.id

    if (position === 'right') {

      let res = await wx.showModal({
        content: "确认删除房屋信息吗？"
      })

      if (res.confirm) {
        await wx.http.delete('/room/' + id)
        this.setData({
          list: this.data.list.filter(item => {
            return item.id != id
          })
        })
      }

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail(event) {

    let { id } = event.mark
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
